2015-09-17.sql 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. if not exists
  2. (select * from syscolumns where id=object_id('tb_ErpPlusPickItems') and name='Plu_OpenSingle')
  3. begin
  4. alter table tb_ErpPlusPickItems add Plu_OpenSingle nvarchar(250) NULL
  5. end
  6. IF NOT EXISTS (SELECT * FROM ::fn_listextendedproperty(N'MS_Description' , N'SCHEMA',N'dbo', N'TABLE',N'tb_ErpPlusPickItems', N'COLUMN',N'Plu_OpenSingle'))
  7. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'接单人' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpPlusPickItems', @level2type=N'COLUMN',@level2name=N'Plu_OpenSingle'
  8. GO
  9. if not exists
  10. (select * from syscolumns where id=object_id('tb_ErpPlusPickItems') and name='Plu_TwoPinsCategory')
  11. begin
  12. alter table tb_ErpPlusPickItems add Plu_TwoPinsCategory nvarchar(20) NULL
  13. end
  14. IF NOT EXISTS (SELECT * FROM ::fn_listextendedproperty(N'MS_Description' , N'SCHEMA',N'dbo', N'TABLE',N'tb_ErpPlusPickItems', N'COLUMN',N'Plu_TwoPinsCategory'))
  15. EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'二销类别' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpPlusPickItems', @level2type=N'COLUMN',@level2name=N'Plu_TwoPinsCategory'
  16. GO
  17. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_ErpPlusPickItems')
  18. BEGIN
  19. DROP VIEW [dbo].Vw_ErpPlusPickItems
  20. END
  21. GO
  22. create View Vw_ErpPlusPickItems
  23. as
  24. SELECT tb_ErpPlusPickItems.ID
  25. ,Plu_OrdNumber as 订单号
  26. ,Plu_Amount as 金额
  27. ,Plu_CreateTime as 创建时间
  28. ,Plu_Goods as 商品名称
  29. ,Plu_RecordedPerson as 录单人编号
  30. ,dbo.fn_CheckUserIDGetUserName(Plu_RecordedPerson) AS 录单人名称
  31. ,Plu_GoodsCosts as 商品成本价
  32. ,Plu_SourceType as 加挑金额来源类型
  33. ,Plu_OpenSingle as 销售人员编号
  34. ,dbo.fn_CheckUserIDGetUserName(Plu_OpenSingle) AS 销售人员名称
  35. ,Plu_TwoPinsCategory as 二销类别编号
  36. , dbo.fn_GetClassCodeToName(Plu_TwoPinsCategory, Plu_TwoPinsCategory) AS 二销类别名称
  37. ,Cus_Name as 客户名称
  38. ,Cus_Name_py as 拼音
  39. ,Cus_Telephone as 电话
  40. ,Ord_OrderClass as 套系类别
  41. FROM tb_ErpPlusPickItems
  42. left join tempTB_AggregationCustomer on Plu_OrdNumber=GP_OrderNumber
  43. left join tb_ErpOrder on Plu_OrdNumber=Ord_Number
  44. GO
  45. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_Customer_PaymentOrders')
  46. BEGIN
  47. DROP VIEW [dbo].Vw_Customer_PaymentOrders
  48. END
  49. GO
  50. create View Vw_Customer_PaymentOrders
  51. as
  52. select
  53. tb_ErpOrder.ID
  54. ,Ord_Number
  55. ,Ord_DividedShop
  56. ,Ord_Type
  57. ,Ord_OrderClass
  58. ,Ord_PhotographyCategory
  59. ,Ord_SeriesName
  60. ,Ord_SeriesPrice
  61. ,Ord_Class
  62. ,GP_OrderNumber
  63. ,GP_CustomerGroupID
  64. ,Cus_Name
  65. ,Cus_Name_py
  66. ,Cus_Telephone
  67. ,M_Cus_CustomerNumber
  68. ,(select stuff((select ','+ OrdPe_OrdersPerson from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('')),1,1,'')) as Ord_OrdersPersonID
  69. ,(select stuff((select ','+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('')),1,1,'')) as Ord_OrdersPerson
  70. ,Ord_CreateDatetime
  71. ,( SELECT count(id) FROM tb_ErpOrderProductList where OPlist_OrderNumber=Ord_Number and OPlist_PickupStatus=0) as PickupStatusCount
  72. from tb_ErpOrder
  73. left join tempTB_AggregationCustomer on Ord_Number=GP_OrderNumber
  74. GO
  75. IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'View_DressSaleRentalOrder')
  76. BEGIN
  77. DROP VIEW [dbo].View_DressSaleRentalOrder
  78. END
  79. GO
  80. create View View_DressSaleRentalOrder
  81. as
  82. SELECT tb_ErpDressSaleRentalOrder.ID,Dsro_Number,Dsro_Type,Dsro_Amount,Dsro_MortgageAmount,Dsro_CustomerNumber
  83. ,Dsro_TakeDressTime,Dsro_ReservationBackTime,Dsro_Remark,Dsro_CreateDateTime,Dsro_CreateName,Dsro_UpdateDateTime,
  84. Dsro_UpdateName,Cus_CustomerNumber,Cus_CustomizeNumber,Cus_Type,Cus_ServiceType,Cus_Grade,Cus_Name,Cus_Sex,Cus_Birthday
  85. ,Cus_BirthdayLunar,Cus_DayForMarriage,Cus_DayForMarriageLunar,Cus_Relations,Cus_QQ,Cus_MicroSignal,Cus_Telephone,Cus_FixedPhone,
  86. Cus_Region,Cus_Address,Cus_WorkUnit,Cus_BabyWeight,Cus_BornHospital,Cus_Zodiac,Cus_CustomerSource,Cus_Status,Cus_LossReason,
  87. Cus_DegreeOfIntent,Cus_TrackName,Cus_Remark,Cus_CreateDateTime,Cus_CreateName,Cus_UpdateDateTime,Cus_UpdateName,dbo.tb_Product(Cus_Name) as Py_Cus_Name
  88. ,dbo.fn_CheckUserIDGetUserName(Dsro_CreateName) as 开单人姓名
  89. FROM tb_ErpDressSaleRentalOrder left join tb_ErpCustomer on Dsro_CustomerNumber=Cus_CustomerNumber
  90. GO